#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    void duplicateZeros(vector<int>& arr) {
        int pcur = 0;
        int dest = -1;
        for (pcur, dest; pcur < arr.size(); pcur++)
        {
            if (arr[pcur] == 0)
            {
                dest += 2;
            }
            else
            {
                dest++;
            }
            if (dest >= arr.size() - 1)
                break;
        }
        if (dest == arr.size())
        {
            arr[arr.size() - 1] = 0;
            pcur--;
            dest -= 2;
        }
        while (pcur >= 0 || dest >= 0)
        {
            if (arr[pcur] == 0)
            {
                arr[dest--] = arr[pcur];
                arr[dest--] = arr[pcur];
                pcur--;

            }
            else
            {
                arr[dest--] = arr[pcur];
                pcur--;
            }
        }

    }
};